#!/bin/bash

#格式化时间
TIME=`date +%F-%H:%M:%S`

rm -rf /app/paasadmin/TcpPingResult/*

#文件过滤路径
SAVE_PATH=/app/paasadmin/TcpPingResult/$TIME"_TcpPingResult"/
sudo /bin/mkdir -p  $SAVE_PATH && chown -R paasadmin:paasadmin $SAVE_PATH

cd $SAVE_PATH && /usr/local/bin/tcping  -x 10  10.145.165.242 8997  > $TIME"_10.145.165.242:8997_".txt
cd $SAVE_PATH && /usr/local/bin/tcping  -x 10  10.145.172.243 9025  > $TIME"_10.145.172.243:9025_".txt
cd $SAVE_PATH && /usr/local/bin/tcping  -x 10  10.145.170.244 10081  > $TIME"_10.145.170.244:10081_".txt
cd $SAVE_PATH && /usr/local/bin/tcping  -x 10  10.145.129.252 9075  > $TIME"_10.145.129.252:9075_".txt
cd $SAVE_PATH && /usr/local/bin/tcping  -x 10  10.145.172.243 9038  > $TIME"_10.145.172.243:9038_".txt

#check_result=`sudo cat /app/paasadmin/tcping_result.txt | grep  timeout|wc -l `
#echo $check_result
#sudo grep -rc "timeout" $SAVE_PATH

#当前源IP 内_
ip_address=`/sbin/ip a s  | grep -iw "eth0\|bond0" | grep -i "10.145." | awk '{print $2}' | awk -F "/" '{print $1}' | head -1`

#内容
CONTENT=`grep -rc "timeout" $SAVE_PATH | awk -F ":" '{if($NF != 0)print}'`


for content in ${CONTENT[@]}
  do
    echo "$ip_address $content"
  done

